<?php

class SetorDao extends Dao {

    public function injectDependencies() {

    }

    //05-04
    public function findById($IDSetor) {
        $this->initConnection();
        $this->tMysqli->escape($IDSetor);
        $StSql = TQuery::getSqlFindSectorById($IDSetor);
        $tQuery = $this->tMysqli->exec($StSql);
        while($ArSetor = mysqli_fetch_assoc($tQuery)) {
            $Setor = new Setor($ArSetor['IDSetor'], $ArSetor['IDDepartamento'], $ArSetor['StSetor'], $this->tMysqli);
        }
        $this->closeConnection();
        return !empty($Setor) ? $Setor : false ;
    }

    public function findAll() {
        $this->initConnection();
        $StSql = TQuery::getSqlFindAllSectors();
        $tQuery = $this->tMysqli->exec($StSql);
        $ArSectors = array();
        while($ArSector = mysqli_fetch_assoc($tQuery)) {
            $Setor = new Setor($ArSector['IDSetor'], $ArSector['IDDepartamento'], $ArSector['StSetor'], $this->tMysqli);
            $ArSectors[] = $Setor;
        }
        $this->closeConnection();
        return $ArSectors;
    }

    public function save($ArDados) {
        $this->initConnection();
        $this->tMysqli->escape($ArDados);
        $StSql = TQuery::getSqlInsertSector($ArDados);
        $this->tMysqli->exec($StSql);
        $BoReturn = $this->tMysqli->lastQueryReturn();
        $this->closeConnection();
        return $BoReturn;
    }

    public function update($Sector) {
        $this->initConnection();
        $StSql = TQuery::getSqlUpdateSector($Sector);
        $this->tMysqli->exec($StSql);
        $BoReturn = $this->tMysqli->lastQueryReturn();
        $this->closeConnection();
        return $BoReturn;
    }

    //29-04
    public function delete($IDSetor) {
        $this->initConnection();
        $this->tMysqli->escape($IDSetor);
        $StSql = TQuery::getSqlDeleteSector($IDSetor);
        $this->tMysqli->exec($StSql);
        $BoReturn = $this->tMysqli->lastQueryReturn();
        $this->closeConnection();
        return $BoReturn;
    }

    //28-05
    public function changeDepartament($IDSetor, $IDNewDepartament) {
        $this->initConnection();
        $this->tMysqli->escape($IDNewDepartament);
        $this->tMysqli->escape($IDSetor);
        $StSql = TQuery::getSqlChangeSector($IDSetor, $IDNewDepartament);
        $this->tMysqli->exec($StSql);
        $BoReturn = $this->tMysqli->lastQueryReturn();
        $this->closeConnection();
        return $BoReturn;
    }

}

?>
